package deque;

import org.junit.Test;

import static org.junit.Assert.*;

import java.util.Comparator;

public class MaxArrayDequeTest {

    // Test case for the constructor that takes a comparator
    @Test
    public void testMaxWithComparator() {
        Comparator<Integer> comparator = Integer::compare;
        MaxArrayDeque<Integer> deque = new MaxArrayDeque<>(comparator);

        // Add elements
        deque.addFirst(3);
        deque.addFirst(1);
        deque.addFirst(5);
        deque.addFirst(2);

        // Test max with the original comparator
        assertEquals((Integer) 5, deque.max());
    }

    @Test
    public void testMaxWithEmptyDeque() {
        Comparator<Integer> comparator = Integer::compare;
        MaxArrayDeque<Integer> deque = new MaxArrayDeque<>(comparator);

        // Test max on an empty deque
        assertNull(deque.max());
    }

    // Test max with a different comparator passed to the max(Comparator<T> c) method
    @Test
    public void testMaxWithDifferentComparator() {
        Comparator<Integer> comparator = Integer::compare;
        MaxArrayDeque<Integer> deque = new MaxArrayDeque<>(comparator);

        deque.addFirst(3);
        deque.addFirst(1);
        deque.addFirst(5);
        deque.addFirst(2);

        // Test max with a custom comparator (for example, reverse order)
        Comparator<Integer> reverseComparator = Comparator.reverseOrder();
        assertEquals((Integer) 1, deque.max(reverseComparator));
    }
@Test
    public void finalTest() {
        Comparator<Integer> comparator = Integer::compare;
        MaxArrayDeque<Integer> deque = new MaxArrayDeque<>(comparator);

        deque.addLast(10);
        deque.addLast(20);
        deque.addLast(30);
        deque.addLast(40);
        deque.addLast(50);
        deque.addLast(60);
        deque.addLast(70);
        deque.addLast(80);
        deque.addLast(90);

        Integer i = deque.removeFirst();
        Integer j = deque.removeLast();
        assertNotEquals(null,i);
        assertNotEquals(null,j);







    }
}

